import org.eclipse.draw2d.ColorConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;
/**
 * 
 * MapEditor is the main class that sets up the display and initializes the Graph canvas.
 *
 */
public class MapEditor {

	private Display d = new Display();
	private Shell shell = new Shell(d);
	private Graph g = new Graph(shell, SWT.NONE);

	/**
	 * 
	 * Sets up the display and the graph. The main event dispatcher runs here.
	 * @return 0
	 */
	int MainLoop()
	{	
		shell.setText("Baphi Map Editor");
		shell.setLayout(new FillLayout());
		shell.setSize(1000, 1000);
		
		// Change default highlight color from bright yellow to cyan.
		g.HIGHLIGHT_COLOR = ColorConstants.cyan;
		g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
		
		// Set up helper functions to deal with nodes and connections
		NodeUtils nu = new NodeUtils(d, g);
		
		// Set up functions to open and save graphs
		BaphiFileHandler bfh = new BaphiFileHandler(g, nu);
		
		// Create menus and dialogs, and handle mouse events
		@SuppressWarnings("unused")
		UIManager mm = new UIManager(d, shell, g, nu, bfh);

		shell.open();

		while (!shell.isDisposed()) {
			while (!d.readAndDispatch()) {
				d.sleep();
			}
		}

		return 0;
	}
	
	/**
	 * 
	 * Main routine of MapEditor
	 * @param args
	 * 
	 */
	public static void main(String[] args)
	{
		System.out.println("Baphi Map Editor v0.1");
		
		MapEditor me = new MapEditor();
		me.MainLoop();
	}
	
}
